﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using Interfaces.Enums;
using Interfaces.RepositoryModels.ExternalModels.FilterModels;
using Interfaces.RepositoryModels.InternalModels.UserRoleModels;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SQLRepositories;

namespace DataProviderIntegrationTests.RepositoryTests
{
    [TestClass]
    public class InitRepoTest
    {
        public class DropInitializer : DropCreateDatabaseAlways<DBEconomicInformationServiceContext>
        {
            protected override void Seed(DBEconomicInformationServiceContext context)
            {
                base.Seed(context);
                
                var users = new List<UserModel>
                    {
                        new UserModel
                            {
                                Email = "asdasd",
                                Id = Guid.NewGuid(),
                                Password = "asdsad",
                                UserName = "ASDASD",
                                CreatedDate = DateTime.Now,
                                ChangedDate = DateTime.Now
                                
                            },
                         new UserModel
                            {
                                Email = "asdasd",
                                Id = Guid.NewGuid(),
                                Password = "asdsad",
                                UserName = "ASDASD",
                                CreatedDate = DateTime.Now,
                                ChangedDate = DateTime.Now
                            }
                    };
                var admins = new List<UserModel>
                    {
                        new UserModel
                            {
                                Email = "asdasd",
                                Id = Guid.NewGuid(),
                                Password = "asdsad",
                                UserName = "ASDASD",
                                CreatedDate = DateTime.Now,
                                ChangedDate = DateTime.Now
                            },
                         new UserModel
                            {
                                Email = "asdasd",
                                Id = Guid.NewGuid(),
                                Password = "asdsad",
                                UserName = "ASDASD",
                                CreatedDate = DateTime.Now,
                                ChangedDate = DateTime.Now
                            }
                    };
                context.Roles.Add(new RoleModel()
                    {
                        Type = RoleType.User,
                        Id = Guid.NewGuid(),
                        Users = users,
                        CreatedDate = DateTime.Now,
                        ChangedDate = DateTime.Now
                    });
                context.Roles.Add(new RoleModel
                    {
                        Id = Guid.NewGuid(),
                        Type = RoleType.Admin,
                        Users = admins,
                        CreatedDate = DateTime.Now,
                        ChangedDate = DateTime.Now
                    });
                context.SectorsFilters.Add(new SectorsFilterModel
                    {
                        Name = "Test",
                        Id = Guid.NewGuid(),
                        User = users[0],
                        CreatedDate = DateTime.Now,
                        ChangedDate = DateTime.Now
                    });
                context.SaveChanges();
            }
        }

        [TestMethod]
        public void CreateDatabase()
        {
            Database.SetInitializer(new DropInitializer());    
            var target = new DBEconomicInformationServiceContext();
            var user = target.Users.FirstOrDefault();
            Assert.IsNotNull(user);
            Assert.IsNotNull(user.Roles);
        }
    }
}
